package com.swiftride.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.swiftride.domain.DriverPoint;
import com.swiftride.mapper.DriverPointMapper;
import com.swiftride.param.PointParam;
import com.swiftride.service.IDriverPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DriverPointServiceImpl implements IDriverPointService {

    @Autowired
    private DriverPointMapper driverPointMapper;

    @Override
    public void save(PointParam pointParam) {
        //开始代驾
        Long driverId = StpUtil.getLoginIdAsLong();

        //调用大数据组件，把司机的实时坐标存储到hbase中
        DriverPoint point = new DriverPoint();
        point.setDriverId(driverId);
        point.setOrderNo(pointParam.getOrderNo());
        point.setLongitude(String.valueOf(pointParam.getLongitude()));
        point.setLatitude(String.valueOf(pointParam.getLatitude()));
        driverPointMapper.save(point);
    }

    @Override
    public List<PointParam> selectByOrderNo(String orderNo) {
        List<DriverPoint> driverPointList = driverPointMapper.selectByOrderNo(orderNo);
        return driverPointList.stream().map(driverPoint -> BeanUtil.copyProperties(driverPoint, PointParam.class)).toList();
    }
}
